<template>
  <view>
   <view class="goods-list">
     <view v-for="(goods,i) in goodsList" :key="i" @click="gotoGoodsDetail(goods)">
       <my-goods :goods="goods"></my-goods>
     </view>
   </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        queryObj:{
          query:'',
          cid:'',
          pagenum:1,
          pagesize:10,
        },
        goodsList:[],
        total:0,
        isloading:false
        
      };
    },
    onLoad(option) {
      this.queryObj.query=option.query || ''
      this.queryObj.cid=option.cid || ''
      
      this.getgoodsList()
    },
    methods:{
      async getgoodsList(cb){
        this.isloading=true
        const {data:res}=await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
        cb && cb() 
        if (res.meta.status!==200){
          return uni.$showMsg()
        }
        this.goodsList=[...res.message.goods,...this.goodsList]
        this.total=res.message.total        
         this.isloading=false
      },
      gotoGoodsDetail(goods){
        uni.navigateTo({
          url:'/subpkg/good_detail/good_detail?goods_id='+goods.goods_id
        })
      }
    },
    onReachBottom(){
      if(this.queryObj.pagenum*this.queryObj.pagesize>=this.queryObj.total) 
      {
        return uni.$showMsg('数据加载完毕了')
        }
      if(this.isloading)return
      this.queryObj.pagenum+=1
      
       this.getgoodsList()
    },
    onPullDownRefresh() {
      this.queryObj.pagenum=1,
      this.queryObj.total=0,
      this.isloading=false,
      this.goodsList=[],
      this.getgoodsList(()=>uni.stopPullDownRefresh())
    },
    
  }
  
</script>

<style lang="scss">

</style>
